
// import axios from 'axios'
import * as api from '../../../http/api'
import http from '../../../http/http'
const state={
  postInsData:[],
  postOutsData:[]
}
const actions={
  postInData({commit},obj){
    console.log(obj) //餐桌号和类型
    // let obj={
    // }
    return http({
      url:api.tableSelectOrder,
      method:'post',
      data:obj
    }).then(res=>{
      // console.log(res.data.dishesList)
      console.log(res.data)
      commit('addInData',res.data.dishesList)
      return res.code
    })
  },
  postOutData({commit},obj){
    console.log(obj)
    return http({
      url:api.takeoutSelectOrderPaging,
      method:'post',
      data:obj
    }).then(res=>{
       console.log(res)
      commit('addOutData',res.data.takeOut)
      return res.code
    })
  }
}
const mutations={
  addInData(state,obj){
    state.postInsData=obj
    // console.log(obj)
  },
  addOutData(state,obj){
    state.postOutsData=obj
    console.log(obj)
  }
}
const getters={
  getPostInsData(state) {
    // console.log(state.postInsData)
    state.postInsData.forEach(item => {
      let myOrderType = {}
      if(item.orderType===0) {
        // console.log(item.orderType)
        myOrderType = {
          value: 0,
          label: '堂食'
        }
      } else if(item.orderType===1) {
        myOrderType = {
          value: 1,
          label: '外卖'
        }
      }
      item.orderType = myOrderType
    });
    // console.log(state.postInsData)
    return state.postInsData
  },
  getPostOutsData(state) {
    console.log(state.postOutsData)
    state.postOutsData.forEach(item => {
      let myOrderType = {}
      if(item.orderType===0) {
        // console.log(item.orderType)
        myOrderType = {
          value: 0,
          label: '堂食'
        }
      } else if(item.orderType===1) {
        myOrderType = {
          value: 1,
          label: '外卖'
        }
      }
      item.orderType = myOrderType
    });
    // console.log(state.postOutsData)
    return state.postOutsData
  },
}
export default{
  state,
  actions,
  mutations,
  getters,
}